package TUILayer;

import java.util.*;
import ControlLayer.PersonCtr;
import ModelLayer.PersonMappe.*;

public class PersonUI
{
    private Scanner keyboard;
    private PersonCtr personCtr;
    
    private boolean running;
    
    
    public PersonUI()
    {
        keyboard = new Scanner(System.in);
        personCtr = new PersonCtr();
        running = true;
    }
    
    /**
     * Person loop
     */
    public void personMenu()
    {
        while(running)
        {
            writeMenu();
            int choise = userInt();
            
            switch(choise)
            {
                case 1:
                    lavTest();
                    break;
                case 2:
                    running = false;
                    break;
                default:
                    forkertInput();
            }
        }
        pause();
        
    }
    
    private void writeMenu()
    {
        System.out.println("\fPerson Menu");
        System.out.println("##########");
        System.out.println("# 1) lav test-objekter");
        System.out.println("# 2) Exit");
        System.out.println();
    }
    
    private int userInt()
    {
        System.out.print("Indtast nummer: ");
        int result = 0;
        result = keyboard.nextInt();
        return result;
    }
    
    private String userString(String navnPaaString)
    {
        System.out.print("Indtast " + navnPaaString + ": ");
        String result = "";
        result = keyboard.nextLine();
        return result;
    }
    
    private void forkertInput()
    {
        System.out.println("Input ikke gyldigt!");
        pause();
    }
    
    private void pause()
    {
        Scanner pause = new Scanner(System.in);
        pause.nextLine();
    }
    
    //menu metoder
    private void lavTest()
    {
        personCtr.createAnsat("ansatTest", "tlfTest1", "adresse_1", "postnr_1", "by_1", "mail_1", "1", "passw_test", "kontoTest");
        System.out.println("Ansat med ID: 1 - blev lavet");
        
        personCtr.createKunde("kortNrTest", "regNrTest", "CCTest", "kundeTest", "tlfTest1", "adresse_2", "postnr_2", "by_2", "mail_2", "2", "leveringsAdresseTest");
        System.out.println("Kunde med ID: 2 - blev lavet");
    }
    
    //andre metoder
    public Person getPerson()
    {
        String id = userString("id");
        Person p = personCtr.getPerson(id);
        if(p == null)
        {
           System.out.println("En person med ID " + id + " blev ikke fundet...");
        }
        
        return p;
    }
}